#include<string>
#include<algorithm>
using std::string;
using std::min;


class Solution {
public:
    int countSubstrings(string s) {
        if (s.size() < 2) return 1;
        
        int n = s.size(), count = n;
        for (int i = 1; i < n; i++) {
            
            for (int k = 1; i-k >= 0 && i+k < n && s[i-k] == s[i+k]; k++ && count++) {}
            int j = i-1;
            for (int k = 1; j-k >= 0 && i+k < n && s[j-k] == s[i+k]; k++ && count++) {}

        }
        return count;
    }
};